<?php
namespace app\adminjcb\controller;

use app\common\controller\AdminBaseController;

/**
 * 矿机管理
 * Class Member
 */
class MachineController extends AdminBaseController {

	protected function _initialize() {
		parent::_initialize();
	}

	/**
	 * 列表
	 * @param string $keyword
	 * @param int    $page
	 * @return mixed
	 */
	public function index() {
		$map = array();
		$goods_list = db('machine')->where($map)->paginate(15, false, get_query());
		$this->assign('list', $goods_list);
		return $this->fetch();
	}

	/**
	 * 更新
	 * @param $id
	 */
	public function update($id) {
		if ($this->request->isPost()) {
			$data['name'] = input('name');
			$data['price'] = input('price');
			$data['note'] = input('note');
			$data['fee'] = input('fee');
			$data['output'] = input('output');
			$data['status'] = input('status');
			if (input('thumb_img')) {
				$data['thumb'] = input('thumb_img');
			}
			if (db('machine')->where('id', $id)->update($data) !== false) {
				$this->success('更新成功');
			} else {
				$this->error('更新失败');
			}
		} else {
			$goods = db('machine')->find($id);
			$this->assign('model', $goods);
			return $this->fetch();
		}
	}

}
